package com.sparrow.manage.company;

import com.sparrow.config.EnvironmentVariables;
import com.sparrow.manage.common.controller.StandardController;
import com.sparrow.manage.common.entity.result.Result;
import com.sparrow.manage.common.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(EnvironmentVariables.MANAGE_ACCESS_PREFIX + "/company")
public class CompanyController extends StandardController<Company> {

    @Autowired
    private CompanyService companyService;

    @RequestMapping("index")
    public String index(Model model){
        Company company = companyService.queryOne();
        if(company == null) company = new Company();
        model.addAttribute("company", company);
        return EnvironmentVariables.MANAGE_TEMPLATE_STORE_PATH + "company/index";
    }

    @ResponseBody
    @RequestMapping("update")
    public Result update(Company company){
        Result result = this.updateEntity(company);
        return result;
    }

    @Override
    protected BaseService getService() {
        return companyService;
    }

    @Override
    protected Result argumentsValidate(Company company) {
        return null;
    }
}
